using System;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using System.Collections.Generic;

namespace DecisionMaking.Domain
{
	[ActiveRecord]
	public class Candidate: ActiveRecordValidationBase<Candidate>
	{
		private IList<CandidateCueValue> values = new List<CandidateCueValue>();
		
		public Candidate ()
		{
		}
		
	    [PrimaryKey(PrimaryKeyType.Native)]
	    public int Id {set; get;}	
		
		[BelongsTo(NotNull = true, UniqueKey = "uix_candidate_name")]
		public Environment Environment {set; get;}
		
		[Property(NotNull = true, UniqueKey = "uix_candidate_name"), ValidateLength(2, 50)]
		public string Name {set; get;}	
		
		[Property]
		public double IndependentVariableValue {set; get;}
		
		[HasMany(typeof(CandidateCueValue), Inverse = true)]
		public IList<CandidateCueValue> Values
		{
			get {return values;}
			set {values = value;}
		}
		
		public override bool Equals (object obj)
		{
			if (obj == null)
				return false;
			if (ReferenceEquals (this, obj))
				return true;
			if (obj.GetType () != typeof(Candidate))
				return false;
			DecisionMaking.Domain.Candidate other = (DecisionMaking.Domain.Candidate)obj;
			return Id == other.Id;
		}


		public override int GetHashCode ()
		{
			unchecked {
				return Id.GetHashCode ();
			}
		}

				
	}
}

